#pragma once

#include <mysql/mysql.h>
#include "../cmdsql/cmdsql.h"
#include <iostream>
#include <memory> 

using std::string;
using std::cout;
using std::endl;

struct Sqlservconfig
{
    string dbserverip;
    string dbusername;
    string dbpassword;
    string dbname;
    Sqlservconfig(
        string dbserverip,\
        string dbusername,\
        string dbpassword,\
        string dbname    \
                    ){
        dbserverip= dbserverip;
        dbusername= dbusername;
        dbpassword= dbpassword;
        dbname    = dbname    ;          
    }

    Sqlservconfig(){
        dbserverip  =  string("127.0.0.1");
        dbusername  =  string("mainuser");
        dbpassword  =  string("Bu1.buqi");
        dbname      =  string("userdb");          
    }

};

extern const Sqlservconfig sqlservconfig;

class thesql :  public cmdsql
{
public:
    thesql(){};
    virtual ~thesql(){};


    virtual void connect(){};

    virtual void insert(){};
    virtual void remove(){};
    virtual void select(){};
    virtual void update(){};
    virtual void upsert(){};

    virtual void displayres(){};

protected:
    string dbserverip;
    string dbusername;
    string dbpassword;
    string dbname;

};




class mysql : public thesql 
{
public:
    mysql();
    virtual ~mysql(){};

    void connect() override;
    void insert() override;
    void remove() override;
    void select() override;
    void update() override;
    void upsert() override;
    void displayres() override;

    // 重载 << 操作符作为成员函数
    friend std::ostream& operator<<(std::ostream& os, const mysql& mysql) {
        // 自定义格式输出
        os << "mysql obj:" << mysql.function<<","<< mysql.key<<","<<mysql.value<<endl;
        return os;
    }

protected:
    MYSQL *conn;
    MYSQL_RES *res;
    MYSQL_ROW row;


private:


};